<?php

/*
 * 详情控制器
 * @author sky
 * create_time 2017-04-23
 */


namespace App\Front\Controllers\Index;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Intervention\Image\Constraint;
use App\Admin\Controllers\Controller;
use App\Admin\Models\Logs;
use App\Front\Models\Cart;
use Session;
use DB;

class CartController extends Controller {


    /*
     * 更多商品列表
     * @author sky
     * create_time 2017-04-23
     */
    public function cart(Request $request) {
    	if($request->session()->get('name')!=""){
        $id = $request->session()->get('name');
        $bookid = Cart::Cart($id);
        $cartlist = DB::table('mini_goods')->whereIn('id',$bookid)->get();
        // dd($cartlist);
        $data['cartlist'] = $cartlist;
	        return view('front.cart',$data);
    	}else{
    		return redirect()->route('login');
    	}
    }

    // 加入购物车
    public function addcart(Request $request){
        $userId = $request->session()->get('nick');
        $bookId = $request->input('id');
        $count = 1;
        $addcart = array(
            'userId' => $userId,
            'bookId' => $request['id'],
            'count' => 1
        );   
        if(Cart::AddCart($addcart)){
            return 'true';
        }else{
            return 'false';
        }
    }
}